package com.ddwl.user.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.user.ProfitApplyQueryBo;
import com.ddwl.schema.bo.user.ProfitApplyRejectBo;
import com.ddwl.schema.bo.user.ProfitApplySubmitBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.user.ProfitApplyVo;
import com.ddwl.user.service.ProfitApplyServer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 类ProfitController.java的实现描述：分销推广申请相关接口
 *
 * @author zach
 * @Date :2020-06-24 15:00.
 */
@Api(tags = "分销推广申请相关接口")
@RequestMapping("/profit/apply")
@Auth(product = BaseEnum.ProductEnum.CONSOLE)
@RestController
public class ProfitApplyController extends BaseController {


    @Resource
    private ProfitApplyServer profitApplyServer;

    @PostMapping
    @Auth(product = BaseEnum.ProductEnum.MALL)
    @ApiOperation("提交代理分销申请,可重复提交")
    public RestVo create(@Valid @RequestBody ProfitApplySubmitBo bo) throws Exception {
        bo.setUserId(getUserId());
        profitApplyServer.submitProfitApply(bo);
        return RestVo.ok();
    }

    @GetMapping("{applyId}")
    @ApiOperation("获取审批详情")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo<ProfitApplyVo> getApply(@PathVariable("applyId") String applyId) {
        return RestVo.ok(profitApplyServer.get(applyId));
    }


    @DeleteMapping("{applyId}")
    @ApiOperation("删除用户代理信息")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo<ProfitApplyVo> delete(@PathVariable("applyId") String applyId) {
        profitApplyServer.delete(applyId);
        return RestVo.ok();
    }

    @GetMapping("/info")
    @ApiOperation("获取用户申请审批详情")
    @Auth(product = BaseEnum.ProductEnum.MALL)
    public RestVo<ProfitApplyVo> getUserApply() {
        return RestVo.ok(profitApplyServer.getUserApply(getUserId()));
    }

    @PostMapping("/page")
    @ApiOperation("获取审批列表分页")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo<PageVo<ProfitApplyVo>> getApply(@RequestBody PageBo<ProfitApplyQueryBo> pageBo) {
        return RestVo.ok(profitApplyServer.page(pageBo));
    }

    @PostMapping("/profitApplyList")
    @ApiOperation("获取身份证审批列表不分页")
    @Auth(product = BaseEnum.ProductEnum.API)
    public RestVo<Integer> queryProfitApplyCount(@RequestBody ProfitApplyQueryBo pageBo) {
        return RestVo.ok(profitApplyServer.queryProfitApplyList(pageBo));
    }


    @PostMapping("/{applyId}/approve")
    @ApiOperation("审批通过")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo approveApply(@PathVariable("applyId") String applyId) {
        profitApplyServer.approveApply(applyId);
        return RestVo.ok();
    }

    @PostMapping("/reject")
    @ApiOperation("审批拒绝")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    public RestVo rejectApply(@RequestBody ProfitApplyRejectBo profitApplyRejectBo) {
        profitApplyServer.rejectApply(profitApplyRejectBo);
        return RestVo.ok();
    }

    @GetMapping("/successful")
    @ApiOperation("查询审批通过的")
    @Auth(product = BaseEnum.ProductEnum.API)
    public RestVo<List<ProfitApplyVo>> successfulApply() {
        return RestVo.ok(profitApplyServer.querySuccessfulApply());
    }

    @PostMapping("/batchSyncApplyUser")
    @ApiOperation("批量订正用户数据")
    @Auth(product = BaseEnum.ProductEnum.API)
    public RestVo batchSyncApplyUser(){
        profitApplyServer.batchSyncApplyUser();
        return RestVo.ok();
    }

    @PostMapping("/walletInfo/correct")
    @ApiOperation("订正用户钱包数据")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE,required = false)
    public RestVo batchCorrectWalletInfo(){
        profitApplyServer.batchCorrectWalletInfo();
        return RestVo.ok();
    }


}
